﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 头像抽奖工具
{
    public class MyPanel : Panel
    {
        public string fileName;
        public MyPanel()
        {
            SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true);
        }

        protected override void OnPaintBackground(PaintEventArgs e)
        {
            //不进行背景的绘制
        }

        protected override void OnPaint(PaintEventArgs e)
        {

            //绘制panel的背景图像
            if (string.IsNullOrEmpty(fileName))
            {
                e.Graphics.FillRectangle(new SolidBrush(Color.White), 0, 0, this.Width, this.Height);
            }
            else
            {
                e.Graphics.FillRectangle(new SolidBrush(Color.White), 0, 0, this.Width, this.Height);
                e.Graphics.DrawImage(Image.FromFile(fileName), 0, 0, this.Width, this.Height);
            }
        }
    }
}
